/**
 * 作者: hxl
 * 日期: 2025-07-08 10:53:27
 * 备注: 用户联盟乱斗成员快照信息表（常驻活动）
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserUnionScuffleMember;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserUnionScuffleMemberWeekModel extends BaseModel implements Model {
    public static final String LISTKEY = "group_list_key.member_id";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // ID
    protected long userId; // 玩家id
    protected long enemyUnionId; // 对手联盟id
    protected long memberId; // 对手成员id
    protected long power; // 成员实力
    protected String partnerList = ""; // 干员列表
    protected String name = ""; // 成员名字
    protected String icon = ""; // 成员头像
    protected int iconFrame; // 头像框
    protected String groupListKey = ""; // 分组key (userid,enemy_unionid)

    public void reset() {
    }

    protected String getKey() {
        return "UserUnionScuffleMemberWeek." + groupListKey + "." + memberId;
    }

    protected String getListKey() {
        return "UserUnionScuffleMemberWeek." + groupListKey;
    }

    protected String getListItemKey() {
        return memberId + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_union_scuffle_member_week"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // ID
        obj.put("userId", userId); // 玩家id
        obj.put("enemyUnionId", enemyUnionId); // 对手联盟id
        obj.put("memberId", memberId); // 对手成员id
        obj.put("power", power); // 成员实力
        obj.put("partnerList", partnerList); // 干员列表
        obj.put("name", name); // 成员名字
        obj.put("icon", icon); // 成员头像
        obj.put("iconFrame", iconFrame); // 头像框
        obj.put("groupListKey", groupListKey); // 分组key (userid,enemy_unionid)
        return obj;
    }

    public PBUserUnionScuffleMember.Builder takeInitBuilder() {
        PBUserUnionScuffleMember.Builder sb = PBUserUnionScuffleMember.newBuilder();
        if (enemyUnionId != 0) {
            sb.setEnemyUnionId(enemyUnionId);
        }
        if (memberId != 0) {
            sb.setMemberId(memberId);
        }
        if (power != 0) {
            sb.setPower(power);
        }
        if (!name.isEmpty()) {
            sb.setName(name);
        }
        if (!icon.isEmpty()) {
            sb.setIcon(icon);
        }
        if (iconFrame != 0) {
            sb.setIconFrame(iconFrame);
        }
        return sb;
    }

    public PBUserUnionScuffleMember.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserUnionScuffleMember.Builder sb = PBUserUnionScuffleMember.newBuilder();
        if (isFieldUpdate("enemyUnionId")) {
            sb.setEnemyUnionId(enemyUnionId);
        }
        if (isFieldUpdate("memberId")) {
            sb.setMemberId(memberId);
        }
        if (isFieldUpdate("power")) {
            sb.setPower(power);
        }
        if (isFieldUpdate("name")) {
            sb.setName(name);
        }
        if (isFieldUpdate("icon")) {
            sb.setIcon(icon);
        }
        if (isFieldUpdate("iconFrame")) {
            sb.setIconFrame(iconFrame);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public long getEnemyUnionId() {
        return enemyUnionId;
    }

    public void putEnemyUnionId(long enemyUnionId) {
        if (this.enemyUnionId != enemyUnionId) {
            this.enemyUnionId = enemyUnionId;
            updateRedisHashField(getKey(), "enemyUnionId", this.enemyUnionId);
        }
    }

    public void addEnemyUnionId(long value) {
        this.enemyUnionId += value;
        updateRedisHashField(getKey(), "enemyUnionId", this.enemyUnionId);
    }

    public long getMemberId() {
        return memberId;
    }

    public void putMemberId(long memberId) {
        if (this.memberId != memberId) {
            this.memberId = memberId;
            updateRedisHashField(getKey(), "memberId", this.memberId);
        }
    }

    public void addMemberId(long value) {
        this.memberId += value;
        updateRedisHashField(getKey(), "memberId", this.memberId);
    }

    public long getPower() {
        return power;
    }

    public void putPower(long power) {
        if (this.power != power) {
            this.power = power;
            updateRedisHashField(getKey(), "power", this.power);
        }
    }

    public void addPower(long value) {
        this.power += value;
        updateRedisHashField(getKey(), "power", this.power);
    }

    public JsonArray getPartnerListArray() {
        if (this.partnerList != null && this.partnerList.length() > 0) {
            return new JsonArray(this.partnerList);
        } else {
            return new JsonArray();
        }
    }

    public String getPartnerList() {
        return partnerList;
    }

    public void putPartnerList(String partnerList) {
        if (!this.partnerList.equals(partnerList)) {
            this.partnerList = partnerList;
            updateRedisHashField(getKey(), "partnerList", this.partnerList);
        }
    }

    public String getName() {
        return name;
    }

    public void putName(String name) {
        if (!this.name.equals(name)) {
            this.name = name;
            updateRedisHashField(getKey(), "name", this.name);
        }
    }

    public String getIcon() {
        return icon;
    }

    public void putIcon(String icon) {
        if (!this.icon.equals(icon)) {
            this.icon = icon;
            updateRedisHashField(getKey(), "icon", this.icon);
        }
    }

    public int getIconFrame() {
        return iconFrame;
    }

    public void putIconFrame(int iconFrame) {
        if (this.iconFrame != iconFrame) {
            this.iconFrame = iconFrame;
            updateRedisHashField(getKey(), "iconFrame", this.iconFrame);
        }
    }

    public void addIconFrame(int value) {
        this.iconFrame += value;
        updateRedisHashField(getKey(), "iconFrame", this.iconFrame);
    }

    public String getGroupListKey() {
        return groupListKey;
    }

    public void putGroupListKey(String groupListKey) {
        if (!this.groupListKey.equals(groupListKey)) {
            this.groupListKey = groupListKey;
            updateRedisHashField(getKey(), "groupListKey", this.groupListKey);
        }
    }

}